package com.wzy.mall.web.servlet.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wzy.mall.model.vo.ResultVO;
import com.wzy.mall.model.vo.clientVO.TypeVO;
import com.wzy.mall.service.client.IndexService;
import com.wzy.mall.service.client.impl.IndexServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class Index {

    private static ObjectMapper jsonMapper = new ObjectMapper();
    private static IndexService indexService = new IndexServiceImpl();

    public static void getType(HttpServletRequest request, HttpServletResponse response) {
        // 没有请求参数 直接调用Service层
        List<TypeVO> typeVOList = indexService.getType();

        try {
            if(typeVOList == null || typeVOList.size() == 0) {
                ResultVO error = ResultVO.error("服务器繁忙！！！");
                response.getWriter().write(jsonMapper.writeValueAsString(error));
            } else {
                ResultVO ok = ResultVO.ok(typeVOList);
                response.getWriter().write(jsonMapper.writeValueAsString(ok));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
